package cn.wolfcode.trip.base.domain;

import com.alibaba.druid.support.json.JSONUtils;
import lombok.Getter;
import lombok.Setter;

import java.util.Date;
import java.util.HashMap;
import java.util.Map;

/**
 * 攻略文章
 */
@Setter
@Getter
public class StrategyDetail extends BaseDomain{
    //攻略文章状态常量
    public static final int STATE_NOMAL =0;//草稿
    public static final int STATE_RELEASE =1;//发布
    public static final int STATE_DISABEL =-1;//禁用

    //攻略文章标题
    private String title;

    //攻略文章创建时间
    private Date createTime;

    //发布时间
    private Date releaseTime;

    //排序
    private Integer sequence;

    //所属的攻略分类
    private StrategyCatalog strategyCatalog;

    //攻略文章的封面图
    private String coverUrl;

    //状态
    private Integer state=STATE_NOMAL;

    //关联文本内容对象
    private StrategyContent strategyContent;

    //状态形容词
    public String getStateName(){
        String str="";
        if(state==STATE_NOMAL){
            str="草稿";
        }else if(state==STATE_RELEASE){
            str="发布";
        }else {
            str="禁用";
        }
        return str;
    }

    //json字符串
    public String getJsonString(){
        Map<String,Object> map=new HashMap<>();
        map.put("id",id);
        map.put("title",title);
        map.put("sequence",sequence);
        map.put("coverUrl",coverUrl);
        map.put("state",state);
        if(strategyCatalog!=null){
            map.put("strategyCatalogId",strategyCatalog.getId());
            if(strategyCatalog.getStrategy()!=null){
                map.put("strategyId",strategyCatalog.getStrategy().getId());
            }
        }
        return JSONUtils.toJSONString(map);
    }

}